import { DotLoading } from 'antd-mobile';
import React, { useReducer } from 'react'
import { Switch, Route, Redirect } from "react-router-dom";
import { initState, reducer } from './reducer/app';
const Login = React.lazy(() => import("./pages/Login/Login"))
const Register = React.lazy(() => import("./pages/Register/Register"))
const Index = React.lazy(() => import("./pages/Index/Index"))
const Home = React.lazy(() => import("./pages/Home/Home"))
const Detail = React.lazy(() => import("./pages/Detail/Detail"))
const Order = React.lazy(() => import("./pages/Order/Order"))
const Coupon = React.lazy(() => import("./pages/Coupon/Coupon"))

export const MyContext = React.createContext()
const App = () => {
  const [state, dispatch] = useReducer(reducer, initState)
  return (
    <div className='app'>
      <MyContext.Provider value={{state,dispatch}}>
        <React.Suspense fallback={<DotLoading color='primary' />}>
          <Switch>
            <Route path="/login" component={Login} />
            <Route path="/register" component={Register} />
            <Route path="/index" component={Index} />
            <Route path="/home" component={Home} />
            <Route path="/detail/:id" component={Detail} />
            <Route path="/order" component={Order} />
            <Route path="/coupon" component={Coupon} />
            <Redirect to="/login" />
          </Switch>
        </React.Suspense>
      </MyContext.Provider>
    </div>
  )
}

export default App